set flagD D
set flagA A
set defchanmodes {
            -clearbans
            +enforcebans      
            +dynamicbans
            +userbans
            -autoop
            -bitch
            +greet
            -protectops
            +statuslog
            +stopnethack
            -revenge
            +autovoice
            -secret
            -shared
            -cycle
        }

# is this being used as X-Bot or as a TCL script?
#  1 = as X-Bot
#  0 = as TCL script
set isXbot "0"

#######
#BINDS#
#######

#OTBN 2.2 Binds - ABO
bind msg - cycle msg:cycle

unbind dcc o|o say *dcc:say
unbind dcc o|- msg *dcc:msg
bind dcc o|n say *dcc:say
bind dcc o msg *dcc:msg
bind pub - $nick otbn.kernal
bind pub - $altnick otbn.kernal
bind pub - $easykey otbn.kernal
bind pub o $easybotnet otbn.kernal
bind mode -o "% -o" deoped
# Added in X-Bot 2003
bind msg - login auth
# Added in X-Bot 2004
bind msg - onjoin msg:onjoin

# Added in X-Bot 2003
bind msg - logon auth
# Added in X-Bot 2003
bind msg - deauth deauth
# Added in X-Bot 2003
bind msg - logoff deauth
# Added in X-Bot 2003
bind msg - logout deauth
bind msg - auth auth
bind sign A * logout
bind pubm - * mscomicwarn
bind kick - * kickwarn
bind bot - auth globauth
# Added in X-Bot 2003
bind bot - login globauth
# Added in X-Bot 2003
bind bot - logon globauth


bind msg - version msg:version
bind msg - credits msg:credits
bind msg - commands msg:commands
bind msg - access msg:access
bind msg - banlist msg:banlist
# Added by OTTech
bind msg - listbans msg:banlist 
bind msg - userlist msg:userlist
# Added by OTTech
bind msg - listusers msg:userlist 
bind msg - help msg:help 
bind msg - admin msg:admin
bind msg - voice msg:voice
bind msg - devoice msg:devoice
bind msg - comment msg:comment
# Added in X-Bot 2003
bind msg - greet msg:comment
# Added in X-Bot 2003
bind msg - sendnote msg:sndnote
bind msg - sndnote msg:sndnote
bind msg - topic msg:topic
bind msg - op msg:op
bind msg - deop msg:deop
bind msg - kick msg:kick
bind msg - ban msg:ban
bind msg - unban msg:unban
bind msg - invite msg:invite
bind msg - usermod msg:usermod
bind msg - killmodes msg:killmodes
# Added by OTTech
bind msg - remuser msg:userdel 
# Added by OTTech
bind msg - deluser msg:userdel 
bind msg - userdel msg:userdel
# Added by OTTech
bind msg - adduser msg:useradd 
bind msg - useradd msg:useradd
bind msg - mode msg:mode
bind msg - say msg:say
bind msg - act msg:act
bind msg - chanstats msg:chanstats
# Added by OTTech
bind msg - chans msg:chans 
bind msg - addchan msg:addchan
# Added by OTTech
bind msg - chanadd msg:addchan
# Added in X-Bot 2003
#bind msg - join msg:addchan
bind msg - remchan msg:remchan
# Added by OTTech
bind msg - chandel msg:remchan 
# Added by OTTech
bind msg - delchan msg:remchan 
# Added by OTTech
#bind msg - part msg:remchan 
# Added in X-Bot 2003
bind msg - global msg:broadcast
bind msg - broadcast msg:broadcast
bind msg - disable msg:disable
# Added by OTTech
bind msg - suspend msg:disable 
bind msg - enable msg:enable
# Added by OTTech
bind msg - unsuspend msg:enable 
bind msg - save msg:save
bind msg - rehash msg:rehash
bind msg - restart msg:restart
# Added in X-Bot 2003
bind msg - sendmsg msg:sndmsg
bind msg - sndmsg msg:sndmsg
# Added in X-Bot 2003
bind msg - sendnotice msg:sndnotice
bind msg - sndnotice msg:sndnotice
bind msg - servers msg:servers
# Added in X-Bot 2003
bind msg - shutdown msg:core
# Added in X-Bot 2003
bind msg - die msg:core
bind msg - core msg:core

proc otbn.kernal {nick host handle chan arg} {

# REMOVED since we are now no longer using Bot-Solutions' Buggy Code
#
# #correct handle
# #the asterisk is never a valid nick and is returned if a handle is not found.
# #corrects otbn.tcl mysterious userfile deletion bug
# if {$handle == "*"} {
#   set handle $nick
# }

  global home botnick defchanoptions defchanmodes
  set defchanoptions {
    chanmode "+nt"
    idle-kick 0 
    need-op { } 
    need-invite { } 
    need-key { } 
    need-unban { } 
    need-limit { } 
    flood-chan 20:60 
    flood-deop 3:10 
    flood-kick 3:10
    flood-join 10:60 
    flood-ctcp 3:60
  }
  set defchanmodes {
    -clearbans 
    +enforcebans 
    +dynamicbans 
    +userbans 
    -autoop 
    -bitch 
    +greet 
    -protectops 
    +statuslog 
    +stopnethack 
    -revenge 
    +autovoice 
    -secret 
    -shared 
    +cycle
  }
  set hitkey [string tolower [lindex $arg 0]]

  if {[string match "#*" $chan] && ([string match {addchan} $hitkey] == 1)} {
    if {[validchan $chan]} {
      set otbn1 [lindex $arg 1]
      set otbn [lindex $arg 3]
      set tcl [lindex $arg 4]
      set botnet [lrange $arg 2 end]
      set botnet2 [lrange $arg 3 end]
      set botnet3 [lrange $arg 4 end]
    } elseif { 1 == 1 } {
      putquick "NOTICE $nick :$chan is not a registered channel."
      return 0
    } 
  } elseif {([string match "*#*" $arg]) && (![string match "*remchan*" $arg])} {
      set chan [lindex $arg 1]
      set otbn1 [lindex $arg 2]
      set otbn [lindex $arg 3]
      set tcl [lindex $arg 4]
      set botnet [lrange $arg 2 end]
      set botnet2 [lrange $arg 3 end]
      set botnet3 [lrange $arg 4 end]		
  } elseif { 1 == 1 } {
      set otbn1 [lindex $arg 1]
      set otbn [lindex $arg 2]
      set tcl [lindex $arg 3]
      set botnet [lrange $arg 1 end]
      set botnet2 [lrange $arg 2 end]
      set botnet3 [lrange $arg 3 end]
  }

  if {[string match {version} $hitkey] == 1} {
    version $nick $host
    return 0
  } elseif {[string match {credits} $hitkey] == 1} {
    credits $nick $host
    return 0
  } elseif {[string match {commands} $hitkey] == 1} {
    commands $nick $handle $chan $otbn1 $host
    return 0
  } elseif {[string match {access} $hitkey] == 1} {	
    do_access $nick $chan $otbn1 $host
    return 0
  
  # Added in X-Bot 2003
  } elseif {[string match {listbans} $hitkey] == 1} {	
    do_banlist $nick $chan $host
    return 0
  } elseif {[string match {banlist} $hitkey] == 1} {	
    do_banlist $nick $chan $host
    return 0
  } elseif {[string match {userlist} $hitkey] == 1} {
    do_userlist $nick $chan $host $otbn1 
    return 0
  } elseif {[string match {help} $hitkey] == 1} {
    help $nick $otbn1 $chan $host $arg
    return 0
  } elseif {[string match {admin} $hitkey] == 1} {
    admin $nick $host
    return 0
  } 



# channel voice / non-disabled user
if {![matchattr $handle o|v $chan] && ![matchattr $handle o|o $chan]} {
  putquick "NOTICE $nick :\0034ERROR - Permission denied."
  return 0
} elseif {[matchattr $handle D]} {
  putquick "NOTICE $nick :\0034ERROR - Permission denied: Your user account is disabled."
  return 0
} elseif {![matchattr $handle A]} {
  putquick "NOTICE $nick :\0034ERROR - Permission denied: Your not authenticated."           
  putquick "NOTICE $nick :You may authenticate yourself by typing /msg $botnick auth <your password>"
  return 0
} 


  if {[string match {voice} $hitkey] == 1} {
    voice $nick $handle $chan $otbn1 $host $botnet
    return 0
  } elseif {[string match {devoice} $hitkey] == 1} {
    devoice $nick $handle $chan $otbn1 $host $botnet
    return 0
  } elseif {[string match {comment} $hitkey] == 1} {
    comment $nick $handle $host $chan $otbn1 $botnet
    return 0 
  
  # Added in X-Bot 2003
  } elseif {[string match {greet} $hitkey] == 1} {
    comment $nick $handle $host $chan $otbn1 $botnet
    return 0 
  
  # Added in X-Bot 2003
  } elseif {[string match {sendnote} $hitkey] == 1} {
    sndnote $nick $handle $otbn1 $botnet2 $host $chan	
    return 0
  } elseif {[string match {sndnote} $hitkey] == 1} {
    sndnote $nick $handle $otbn1 $botnet2 $host $chan	
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {deauth} $hitkey] == 1} {
    deauth $nick $host $handle null
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {logout} $hitkey] == 1} {
    deauth $nick $host $handle null
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {logoff} $hitkey] == 1} {
    deauth $nick $host $handle null
    return 0
  }

# channel op
if {![matchattr $handle o|o $chan]} {
  putquick "NOTICE $nick :\0034ERROR - Permission denied."
  return 0
}

  if {[string match {topic} $hitkey] == 1} {
    pub_topic $nick $chan $botnet $host
    return 0
  } elseif {[string match {op} $hitkey] == 1} {
    op $nick $chan $otbn1 $host $botnet
    return 0       
  } elseif {[string match {deop} $hitkey] == 1} {
    deop $nick $chan $host $otbn1 $botnet $handle
    return 0
  } elseif {[string match {kick} $hitkey] == 1} {
    kick $nick $handle $chan $host $otbn1 $botnet2
    return 0
  } elseif {[string match {ban} $hitkey] == 1} {
    ban $nick $handle $chan $otbn1 $otbn $botnet2 $botnet3 $host 
    return 0
  } elseif {[string match {unban} $hitkey] == 1} {
    unban $nick $handle $chan $otbn1 $host
    return 0
  } elseif {[string match {invite} $hitkey] == 1} {
    invite $nick $handle $host $chan $otbn1
    return 0
  # added by |nsid3r
  } elseif {[string match {onjoin} $hitkey] == 1} {
    bot-onjoin_tcl $nick $host $handle $chan $arg
    return 0
  }

# channel co-admin
if {![matchattr $handle o|m $chan]} {
  putquick "NOTICE $nick :\0034ERROR - Permission Denied."
  return 0
}

  if {[string match {usermod} $hitkey] == 1} {
    usermod $nick $handle $chan $otbn1 $otbn $tcl $host
    return 0
  } elseif {[string match {killmodes} $hitkey] == 1} {
    killmodes $nick $chan $host
    return 0
  } elseif {[string match {userdel} $hitkey] == 1} {
    userdel $nick $handle $chan $otbn1 $otbn $host
    return 0	
  
  # Added in X-Bot 2003
  } elseif {[string match {deluser} $hitkey] == 1} { 
    userdel $nick $handle $chan $otbn1 $otbn $host
    return 0	
  
  # Added in X-Bot 2003
  } elseif {[string match {remuser} $hitkey] == 1} {
    userdel $nick $handle $chan $otbn1 $otbn $host
    return 0	
  
  # Added in X-Bot 2003
  } elseif {[string match {adduser} $hitkey] == 1} {
    useradd $nick $handle $chan $otbn1 $host $otbn $tcl
    return 0
  } elseif {[string match {useradd} $hitkey] == 1} {
    useradd $nick $handle $chan $otbn1 $host $otbn $tcl
    return 0
  } elseif {[string match {mode} $hitkey] == 1} {
    mode $nick $chan $botnet $host
    return 0
  #OTBN 2.2 Addons
  } elseif {[string match {cycle} $hitkey] == 1} {
    cycle $nick $host $handle $chan
    return 0
  }

# channel owner
if {![matchattr $handle o|n $chan]} {
  putquick "NOTICE $nick :\0034ERROR - Permission Denied."
  return 0
}

  if {[string match {say} $hitkey] == 1} {
    say $nick $chan $botnet $host
    return 0
  } elseif {[string match {act} $hitkey] == 1} {
    act $nick $chan $host $botnet
    return 0
  } 

if {![matchattr $handle o]} {
  putquick "NOTICE $nick :\0034ERROR - Permission Denied."
  return 0
}
  
  # Added in X-Bot 2003
  if {[string match {chans} $hitkey] == 1} {
    chanstats $nick $host
    return 0
  } elseif {[string match {chanstats} $hitkey] == 1} {
    chanstats $nick $host
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {chanadd} $hitkey] == 1} {
    addchan $nick $otbn1 $host $handle
    return 0
  
# Added in X-Bot 2003 - not work, probably conflicting with another script
#if {[string match {join} $hitkey] == 1} {
#  addchan $nick $otbn1 $host $handle
#  return 0
#  }
  } elseif {[string match {addchan} $hitkey] == 1} {
    addchan $nick $otbn1 $host $handle
    return 0
  } elseif {[string match {remchan} $hitkey] == 1} {
    remchan $nick $chan $otbn1 $handle $host
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {delchan} $hitkey] == 1} {
    remchan $nick $chan $otbn1 $handle $host
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {chanrem} $hitkey] == 1} {
    remchan $nick $chan $otbn1 $handle $host
    return 0
  
# Added in X-Bot 2003 - not work, probably conflicting with another script
#if {[string match {part} $hitkey] == 1} {
#  remchan $nick $chan $otbn1 $handle $host
#  return 0
#  }
  # Added in X-Bot 2003
  } elseif {[string match {chandel} $hitkey] == 1} {
    remchan $nick $chan $otbn1 $handle $host
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {global} $hitkey] == 1} {
    broadcast $nick $host $botnet
    return 0
  } elseif {[string match {broadcast} $hitkey] == 1} {
    broadcast $nick $host $botnet
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {suspend} $hitkey] == 1} {
    disable $nick $handle $host $chan $otbn1
    return 0
  } elseif {[string match {disable} $hitkey] == 1} {
    disable $nick $handle $host $chan $otbn1
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {unsuspend} $hitkey] == 1} {
    enable $nick $host $chan $otbn1
    return 0
  } elseif {[string match {enable} $hitkey] == 1} {
    enable $nick $host $chan $otbn1
    return 0
  }

if {![matchattr $handle m]} {
  putquick "NOTICE $nick :\0034ERROR - Permission Denied."
  return 0
}

  if {[string match {save} $hitkey] == 1} {
    do_save $nick $host
    return 0	
  } elseif {[string match {rehash} $hitkey] == 1} {
    do_rehash $nick $host
    return 0
  } elseif {[string match {restart} $hitkey] == 1} {
    do_restart $nick $host 
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {sendmsg} $hitkey] == 1} {
    sndmsg $nick $otbn1 $host $botnet2
    return 0
  } elseif {[string match {sndmsg} $hitkey] == 1} {
    sndmsg $nick $otbn1 $host $botnet2
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {sendnotice} $hitkey] == 1} {
    sndnotice $nick $otbn1 $host $botnet2
    return 0
  } elseif {[string match {sndnotice} $hitkey] == 1} {
    sndnotice $nick $otbn1 $host $botnet2
    return 0
  } elseif {[string match {servers} $hitkey] == 1} {
    servers $nick $host
    return 0
  }

if {![matchattr $handle n]} {
  putquick "NOTICE $nick :\0034ERROR - Permission Denied."
  return 0
  }

  # Added in X-Bot 2003
  if {[string match {shutdown} $hitkey] == 1} {
    core $nick $host $handle 
    return 0
  # Added in X-Bot 2003
  } elseif {[string match {die} $hitkey] == 1} {
    core $nick $host $handle 
    return 0
  } elseif {[string match {core} $hitkey] == 1} {
    core $nick $host $handle 
    return 0
  } 
}